cd "F:\Dropbox\School\Research Projects\Populism\Articles\Populist Psychology\Submission files\JOP 2020\Final\Replication files"

use "study 3 prepped.dta", clear

*generates two-point treatment that only tests the effect of cult and econ threat, rather than specific emotions
*Redoes the label so that everything looks good on the graph
label define regionlab1 1 "Southeast" 2 "Northeast" 3 "Midwest" 4 "West" 5 "Southwest" 6 "Non-continental US"
label values region regionlab1
label define treatlab1 0 "Control" 1 "Cultural Threat" 2 "Economic Threat, Fear" 3 "Economic Threat, Anger"
label values treat treatlab1 

*************************
*********makes graphs****
*************************

*saves a partyid variable for the ft categorization
gen left = partyid
gen right = partyid

recode left(1 2=1) (3 4 5 6 7=0)
recode right (6 7=1) (1 2 3 4 5=0)

gen left2=left
gen right2=right 

replace left2=1 if partyid == 3
replace right2=1 if partyid == 5

gen treat3pt = treat
recode treat3pt (3=2), copyrest
label define treat3lab 0 "Control" 1 "Cultural Threat" 2 "Economic Threat"
label values treat3pt treat3lab

label define treat2 0 "Control" 1 "Cultual Threat" 2 "Economic Crisis, Threat" 3 "Economic Crisis, Grievance"
label values treat treat2 

*generates pop agg variable
sem(POP->ant1 ant2 ppl1 ppl2), var(POP@1) method(mlmv)
predict pop, latent


*w emotions
lab var pp "Punitivism"
lab var dec "Declinism"
lab var lwprod "Producerism"
lab var rwprod "Auth. Producerism"
lab var socvic "Social Victimization"
lab var auth "Authoritarianism"
lab var rs "Regime Support"
lab var soct "Sociotropic Evaluation"
lab var anger "Anger"
lab var fear "Fear"
lab var gender "Gender"
lab var region "Region"
lab var partyid "Party Identification"
lab var ed "Education"
lab var income "Income"
lab var race "Race"
lab var latino "Latino"
lab var age "Age"
label define gender 1 "Male" 2 "Female"
label values gender gender
label define race 1 "White" 2 "Black" 3 "Other"
label values race race
label define latino 1 "Not Latino" 2 "Latino"
label values latino latino
lab var ppl "Popularism"
lab var ant "Antielitism"
lab var man "Manichaeism"
lab var cultanx "Cultural Discontent"
lab var pop "Populism"

foreach var of varlist ed income age partyid anger fear soct lwprod rwprod dec man pp rs auth ppl ant socvic rbe perf consp cultanx pop {
qui sum `var'
replace `var' = (`var' - `r(min)') / (`r(max)'-`r(min)')
}

*on sanders and trump*

tobit ft_trump ant ppl man cultanx anger fear i.gender i.region ed income age i.race latino if right2 ==1, ll(0) ul(100)
estimates store b
tobit ft_sanders ant ppl man cultanx anger fear i.gender i.region ed income age i.race latino if left2 ==1, ll(0) ul(100)
estimates store a

coefplot a, bylabel("Sanders Support," "Dems") drop(_cons) xline(0) || /*
*/b, bylabel("Trump Support," "Reps") drop(_cons) xline(0) || /*
*/, byopts(row(1)) msize(vsmall) graphregion(color(white)) bgcolor(white)
